package com.devg.file.web.file.controller;

import com.devg.file.web.base.model.ResultModel;
import com.devg.file.web.file.service.FileService;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/upload")
@Controller
public class FileController {

  @Autowired
  private FileService fileService;

  @ResponseBody
  @RequestMapping("/uploadFile")
  public Map<String, Object> uploadFile(@RequestParam("file") MultipartFile file, String bucketName) throws Exception {
    return fileService.baseUploadFile(file, bucketName);
  }

  @ResponseBody
  @RequestMapping("/uploadFileRandom")
  public Map<String, Object> uploadFileRandom(@RequestParam("file") MultipartFile file, String bucketName) throws Exception {
    return fileService.baseUploadFile(file, bucketName, true);
  }

  @ResponseBody
  @RequestMapping("/uploadFileSync")
  public Map<String, Object> uploadFileSync(@RequestParam("file") MultipartFile file, String fileId, String filePath) throws Exception {
    return fileService.uploadFileSync(file, fileId, filePath);
  }

  @ResponseBody
  @RequestMapping("/deleteFile")
  public Map<String, Object> deleteFile(@RequestParam("filePath") String filePath) throws Exception {
    return fileService.deleteFile(filePath);
  }

  @ResponseBody
  @RequestMapping("/file/list")
  public ResultModel list(@RequestBody Map<String, Object> params) {
    return fileService.list(params);
  }

  @ResponseBody
  @RequestMapping("/file/syncConfigList")
  public ResultModel syncConfigList(@RequestBody Map<String, Object> params) {
    return fileService.syncConfigList(params);
  }

  @ResponseBody
  @RequestMapping("/file/syncConfigSet")
  public ResultModel syncConfigSet(@RequestBody Map<String, Object> params) {
    return fileService.syncConfigSet(params);
  }
}
